<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.0/css/bootstrap.css" rel="stylesheet">
  <style>
    .ani-enter{
      transform: translateX(-500px);
      opacity:0;
    }
    .ani-leave-to{
      transform: translateX(500px);
      opacity:0;
    }
    .ani-enter-active,.ani-leave-active{
      transition: all .5s;
    }
  </style>
</head>
<body>
  <div id="app">
    <div class="container">
      <h2 class="text-center">todoList</h2>
      <h3 class="text-center">今日事、今日毕</h3>
      <div class="todoHeader row center-block" style="max-width:600px;">
        <div class="col-md-10 col-sm-10">
          <input  type="text" v-model.trim="inputTxt" class="form-control">
        </div>
        <div class="col-md-2 col-sm-2">
          <button class="btn btn-primary"
            @click="addTodo"
          >增加</button>
        </div>
      </div>
      <div class="todoContent center-block" style="max-width:600px;margin-top:10px">
        <ul class="list-group">
          <li 
            class="list-group-item text-center"
            v-if="!todos.length"
            >
            暂无待办事项
          </li>
          <transition-group name="ani">
            <li 
              v-for="(todo,index) in todos"
              class="list-group-item"
              :key="index"              
              >
              
            {{ todo.content }}
            <button class="btn btn-danger" @click="del(index)">删除</button>
          </li>
          </transition-group>
        </ul>
      </div>
    </div>
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: '#app',
      data: {
        inputTxt: '',
        todos: [
        ]
      },
      methods: {
        del(index){
          this.todos.splice(index, 1)
        },
        addTodo () {
          if(this.inputTxt == ''){
            return;
          }
          // 添加一个待办事项
          this.todos.push({
            content: this.inputTxt,
            isCompleted: false
          })
          //增加后清除 表单内容 方便下次输入
          this.inputTxt = "";
        }
      }
    })
  </script>
</body>
</html>